/***
 *
 * 一个用于导出数据为文件并提供下载的类
 *
 * Daniel
 *
 * 2018.04.13
 * **/
define(function () {
    var file = function () {
        this.link = document.createElement( 'a' );
        this.link.style.display = 'none';
        document.body.appendChild( this.link ); // Firefox workaround, see #6594
        
    };
    file.prototype.saveString = function ( text, filename ) {
        
        this.save( new Blob( [ text ], { type: 'text/plain' } ), filename );
        
    };
    
    file.prototype.save = function ( blob, filename ) {
        
        this.link.href = URL.createObjectURL( blob );
        this.link.download = filename || 'data.json';
        this.link.click();
        
        // URL.revokeObjectURL( url ); breaks Firefox...
        
    }
    return file;
    
});
